package com.tbsoft.ehr.model;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 考勤登记对象
 * @author lizhenhua
 *
 */
@Entity
@Table(name="EHR_ATTENDANCE")
public class Attendance extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private int id;	
	//日期
	private Date adDate;
	//缺勤工时
	private BigDecimal hours;
	//缺勤类型
	private String adType;
	//备注/说明
	private String remark;
	//所在服务客户
	private ServiceCustomer serviceCustomer;
	//档案信息
	private StaffInfo staff;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="AD_DATE",columnDefinition="date",nullable=false)
	public Date getAdDate() {
		return adDate;
	}
	public void setAdDate(Date adDate) {
		this.adDate = adDate;
	}
	
	@Column(name="AD_HOURS",precision=6,scale=2,nullable=false)
	public BigDecimal getHours() {
		return hours;
	}
	public void setHours(BigDecimal hours) {
		this.hours = hours;
	}
	
	@Column(name="AD_TYPE",length=20,nullable=false)
	public String getAdType() {
		return adType;
	}
	public void setAdType(String adType) {
		this.adType = adType;
	}
	
	@Column(name="REMARK",length=250)
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	@ManyToOne
	@JoinColumn(name="SC_ID")
	public ServiceCustomer getServiceCustomer() {
		return serviceCustomer;
	}
	public void setServiceCustomer(ServiceCustomer serviceCustomer) {
		this.serviceCustomer = serviceCustomer;
	}
	
	@ManyToOne
	@JoinColumn(name="STAFF_ID")
	public StaffInfo getStaff() {
		return staff;
	}
	public void setStaff(StaffInfo staff) {
		this.staff = staff;
	}	
	
	@Override
	public boolean equals(Object obj){
		if(obj instanceof Attendance){
			Attendance ad =(Attendance)obj;
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String adStr = sdf.format(ad.getAdDate());
			String thsStr = sdf.format(this.adDate);
			return thsStr.equals(adStr);
		}
		return false;
	}
}
